def binary_search(a_list, item):
    first = 0
    last = len(a_list) - 1  # 索引是从0开始的，长度是从1开始的
    found = False

    while first <= last and not found:
        midpoint = (first + last) // 2
        if a_list[midpoint] == item:
            found = True
            break
        else:
            if item < a_list[midpoint]:
                last = midpoint - 1
            else:
                first = midpoint + 1

    return found


if __name__ == '__main__':
    a_list = [1, 11, 23, 1, 6, 5, 44]
    a_list.sort()
    print(binary_search(a_list, 11))
    print(binary_search(a_list, 12))